class Post < ActiveRecord::Base
  belongs_to :user
  has_many :comments
  has_attached_file :file

  
  def rate
    sum=0
    self.comments.each do |c|
      sum += c.rating
    end
    if(self.comments.length==0) 
      return nil
    else
      return sum/self.comments.length 
    end
  end
  
  
end
